
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class MyCanvas extends GameCanvas implements Runnable{
    private volatile Thread thread;
    public final GameLayerManager layerManager;
    private Graphics graphics = getGraphics();
    public final int DISP_WIDTH;
    public final int DISP_HEIGHT;
    
    public MyCanvas(){
        super(false);
        DISP_WIDTH = getWidth();
        DISP_HEIGHT = getHeight();
        layerManager = new GameLayerManager(this);
        new MyGesture(this);
    }

    // When the game canvas is hidden, stop the thread.
    protected void hideNotify() {
        thread = null;
        System.out.println("...thread stopped");
    }

    // When the canvas is shown, start a thread to
    // run the game loop.
    protected void showNotify() {
        thread = new Thread(this);
        thread.start();
        System.out.println("thread started...");
    }

    // The game loop.
    public void run() {
        while (thread != null) {
            layerManager.paint(graphics);
            flushGraphics();
            try {
                Thread.currentThread().sleep(30);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }
/////////////////////
}
